//*****************************************************************************
// Vizzini Game Framework (http://vizzini.sourceforge.net)
// Copyright (c) 2004-2005 Vizzini.org
// Admin jmthompson_97@users.sourceforge.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package app.util;

import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;


/**
 * Provides a table cell renderer for a hyperlink.
 *
 * @author   Jeffrey M. Thompson
 * @version  v0.2
 * @since    v0.2
 */
public class HyperlinkCellRenderer extends DefaultTableCellRenderer
{
    /** Serial version UID. */
    private static final long serialVersionUID = 1L;

    /** Logger. */
    private static final Logger LOGGER = Logger.getLogger(
            HyperlinkCellRenderer.class.getName());

    /** HTML prefix. */
    private static final String PREFIX = "<html><a href=''>";

    /** HTML suffix. */
    private static final String SUFFIX = "</a></html>";

    /**
     * Returns the component used for drawing the cell. This method is used to
     * configure the renderer appropriately before drawing.
     *
     * @since  v0.2
     */
    @Override
	public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column)
    {
        JLabel answer = (JLabel)super.getTableCellRendererComponent(table,
                value, isSelected, hasFocus, row, column);

        if (value instanceof String)
        {
            // Wrap the value in an HTML anchor tag.
            StringBuffer sb = new StringBuffer();
            sb.append(PREFIX);
            sb.append(value);
            sb.append(SUFFIX);

            String link = sb.toString();

            if (LOGGER.isLoggable(Level.FINER))
            {
                LOGGER.finer("link = " + link);
            }

            answer.setText(link);
        }

        return answer;
    }
}